<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - src/caffe/internal_thread.cpp</title>
  <link rel="stylesheet" type="text/css" href="../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../index.html">top level</a> - <a href="index.html">src/caffe</a> - internal_thread.cpp<span style="font-size: 80%;"> (source / <a href="internal_thread.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">23</td>
            <td class="headerCovTableEntry">28</td>
            <td class="headerCovTableEntryMed">82.1 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:25:26</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">8</td>
            <td class="headerCovTableEntry">9</td>
            <td class="headerCovTableEntryMed">88.9 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #include &lt;boost/thread.hpp&gt;</a>
<span class="lineNum">       2 </span>            : #include &lt;exception&gt;
<span class="lineNum">       3 </span>            : 
<span class="lineNum">       4 </span>            : #include &quot;caffe/internal_thread.hpp&quot;
<span class="lineNum">       5 </span>            : #include &quot;caffe/util/math_functions.hpp&quot;
<span class="lineNum">       6 </span>            : 
<a name="7"><span class="lineNum">       7 </span>            : namespace caffe {</a>
<span class="lineNum">       8 </span>            : 
<span class="lineNum">       9 </span><span class="lineCov">          2 : InternalThread::~InternalThread() {</span>
<span class="lineNum">      10 </span><span class="lineCov">          1 :   StopInternalThread();</span>
<a name="11"><span class="lineNum">      11 </span><span class="lineCov">          1 : }</span></a>
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span><span class="lineCov">          3 : bool InternalThread::is_started() const {</span>
<span class="lineNum">      14 </span><span class="lineCov">          3 :   return thread_ &amp;&amp; thread_-&gt;joinable();</span>
<a name="15"><span class="lineNum">      15 </span>            : }</a>
<span class="lineNum">      16 </span>            : 
<span class="lineNum">      17 </span><span class="lineCov">        104 : bool InternalThread::must_stop() {</span>
<span class="lineNum">      18 </span><span class="lineCov">        104 :   return thread_ &amp;&amp; thread_-&gt;interruption_requested();</span>
<a name="19"><span class="lineNum">      19 </span>            : }</a>
<span class="lineNum">      20 </span>            : 
<span class="lineNum">      21 </span><span class="lineCov">          1 : void InternalThread::StartInternalThread() {</span>
<span class="lineNum">      22 </span><span class="lineCov">          2 :   CHECK(!is_started()) &lt;&lt; &quot;Threads should persist and not be restarted.&quot;;</span>
<span class="lineNum">      23 </span>            : 
<span class="lineNum">      24 </span>            :   int device = 0;
<span class="lineNum">      25 </span>            : #ifndef CPU_ONLY
<span class="lineNum">      26 </span>            :   CUDA_CHECK(cudaGetDevice(&amp;device));
<span class="lineNum">      27 </span>            : #endif
<span class="lineNum">      28 </span>            :   Caffe::Brew mode = Caffe::mode();
<span class="lineNum">      29 </span><span class="lineCov">          1 :   int rand_seed = caffe_rng_rand();</span>
<span class="lineNum">      30 </span>            :   int solver_count = Caffe::solver_count();
<span class="lineNum">      31 </span>            :   int solver_rank = Caffe::solver_rank();
<span class="lineNum">      32 </span>            :   bool multiprocess = Caffe::multiprocess();
<span class="lineNum">      33 </span>            : 
<span class="lineNum">      34 </span>            :   try {
<span class="lineNum">      35 </span><span class="lineCov">          2 :     thread_.reset(new boost::thread(&amp;InternalThread::entry, this, device, mode,</span>
<span class="lineNum">      36 </span><span class="lineCov">          2 :           rand_seed, solver_count, solver_rank, multiprocess));</span>
<span class="lineNum">      37 </span><span class="lineNoCov">          0 :   } catch (std::exception&amp; e) {</span>
<span class="lineNum">      38 </span><span class="lineNoCov">          0 :     LOG(FATAL) &lt;&lt; &quot;Thread exception: &quot; &lt;&lt; e.what();</span>
<span class="lineNum">      39 </span>            :   }
<a name="40"><span class="lineNum">      40 </span><span class="lineCov">          1 : }</span></a>
<span class="lineNum">      41 </span>            : 
<span class="lineNum">      42 </span><span class="lineCov">          1 : void InternalThread::entry(int device, Caffe::Brew mode, int rand_seed,</span>
<span class="lineNum">      43 </span>            :     int solver_count, int solver_rank, bool multiprocess) {
<span class="lineNum">      44 </span>            : #ifndef CPU_ONLY
<span class="lineNum">      45 </span>            :   CUDA_CHECK(cudaSetDevice(device));
<span class="lineNum">      46 </span>            : #endif
<span class="lineNum">      47 </span>            :   Caffe::set_mode(mode);
<span class="lineNum">      48 </span><span class="lineCov">          1 :   Caffe::set_random_seed(rand_seed);</span>
<span class="lineNum">      49 </span>            :   Caffe::set_solver_count(solver_count);
<span class="lineNum">      50 </span>            :   Caffe::set_solver_rank(solver_rank);
<span class="lineNum">      51 </span>            :   Caffe::set_multiprocess(multiprocess);
<span class="lineNum">      52 </span>            : 
<span class="lineNum">      53 </span><span class="lineCov">          1 :   InternalThreadEntry();</span>
<a name="54"><span class="lineNum">      54 </span><span class="lineCov">          1 : }</span></a>
<span class="lineNum">      55 </span>            : 
<span class="lineNum">      56 </span><span class="lineCov">          2 : void InternalThread::StopInternalThread() {</span>
<span class="lineNum">      57 </span><span class="lineCov">          2 :   if (is_started()) {</span>
<span class="lineNum">      58 </span><span class="lineCov">          1 :     thread_-&gt;interrupt();</span>
<span class="lineNum">      59 </span>            :     try {
<span class="lineNum">      60 </span><span class="lineCov">          1 :       thread_-&gt;join();</span>
<span class="lineNum">      61 </span><span class="lineNoCov">          0 :     } catch (boost::thread_interrupted&amp;) {</span>
<span class="lineNum">      62 </span><span class="lineNoCov">          0 :     } catch (std::exception&amp; e) {</span>
<span class="lineNum">      63 </span><span class="lineNoCov">          0 :       LOG(FATAL) &lt;&lt; &quot;Thread exception: &quot; &lt;&lt; e.what();</span>
<span class="lineNum">      64 </span>            :     }
<span class="lineNum">      65 </span>            :   }
<a name="66"><span class="lineNum">      66 </span><span class="lineCov">          2 : }</span></a>
<span class="lineNum">      67 </span>            : 
<span class="lineNum">      68 </span><span class="lineCov">          3 : }  // namespace caffe</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
